package com.example.administrator.myapplication.utli;

import android.content.Context;
import android.content.res.AssetManager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2020/12/14.
 */

public class GetJsonDataUtil {

    public String getJson(Context context,String filename){
        //创建数据缓存器（空间）
        StringBuilder stringBuilder =new StringBuilder();
        //获取本地数据资源管理器

        try {
            AssetManager assetManager =context.getAssets();

            BufferedReader reader =new BufferedReader(new InputStreamReader(assetManager.open(filename)));
            String line;
            while ((line=reader.readLine()) !=null){
                stringBuilder.append(line);

            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return stringBuilder.toString();
    }
}
